<%@ taglib uri="/WEB-INF/eam-tag.tld" prefix="eam" %>

<%@ page import="com.sbdcpn.utils.factory.FactoryUtil,
				com.sbdcpn.utils.system.FunUtil,
				com.sbdcpn.utils.system.SysCollistUtil,
				com.sbdcpn.page.utils.PageStyleConstMessages,
				com.sbdcpn.utils.tools.CommonFun,
				com.sbdcpn.utils.db.BaseDAO,
				com.sbdcpn.page.utils.RequestUtil,
				com.sbdcpn.page.utils.PageUtilMethod,
				java.math.BigDecimal,
				java.util.List,
				java.util.Map" %>

<%

	String strSQL1 = "select nvl(sum(v_fina_give_send_detail.out_sum),0.00) as pagenum,nvl(sum(v_fina_give_send_detail.send_qty),0.00) as send_qty from v_fina_give_send_detail";

	String strWhere1 = RequestUtil.getStringParameter(request ,"where_sql");
	String strValue1 = RequestUtil.getStringParameter(request ,"where_value");
	String strType1 = RequestUtil.getStringParameter(request ,"where_type");
	Map mpCnt = null;
	Map mpCntste = null;
	Map mpCntmat = null;
	BaseDAO _dao = BaseDAO.getInstance();
	System.out.println("strWhere1= "+strWhere1);
	
	if (strWhere1.indexOf("notDoQuery") == -1) {
		if (!strValue1.equals("")) {
			mpCnt = _dao.queryOneRow(strSQL1 + " where material_diff not in ('03','04') and " + strWhere1 ,new String[]{strValue1 ,strType1});
			//System.out.println("-----------" + strSQL1 + " where " + strWhere1);
			mpCntste = _dao.queryOneRow(strSQL1 + " where material_diff = '04'  and " + strWhere1 ,new String[]{strValue1 ,strType1});
			mpCntmat = _dao.queryOneRow(strSQL1 + " where material_diff = '03'  and  " + strWhere1 ,new String[]{strValue1 ,strType1});

		} else {
			mpCnt = _dao.queryOneRow(strSQL1 + " where  not in ('03','04') and  " + strWhere1);
			mpCntste = _dao.queryOneRow(strSQL1 + " where material_diff = '04'  and  " + strWhere1);
			mpCntmat = _dao.queryOneRow(strSQL1 + " where material_diff = '03'  and  " + strWhere1);
		}
	} else {
		mpCnt = FactoryUtil.newMap();
		mpCntste = FactoryUtil.newMap();
		mpCntmat = FactoryUtil.newMap();
		mpCnt.put("pagenum" ,"0.00");
		mpCntste.put("pagenum" ,"0.00");
		mpCntmat.put("pagenum" ,"0.00");
		mpCnt.put("send_qty" ,"0.00");
		mpCntste.put("send_qty" ,"0.00");
		mpCntmat.put("send_qty" ,"0.00");
	}


%>


<SCRIPT LANGUAGE="JavaScript">
<!--
function f_account(){
	var leftObj = window.top.frames("treeFrame");
	//alert(leftObj.location);
	var date = document.all("account_flag").value;
	var costUnitID = document.all("cost_unit").value;
	if (date == "" || date == null) return ;
/*
	var paramUrl = "?funcid=FINANCE_OUT_BILL_DATE";
	paramUrl += "&pageType=grid";
	paramUrl += "&where_sql=v_finance_dept_unio_date.send_date = ?";
	paramUrl += "&where_type=string";
	paramUrl += "&where_value=" +date ;
	//paramUrl += "&=";

*/

	var paramUrl = "?account_flag=" + date;
	paramUrl += "&costUnitID=" + costUnitID;
	var href = leftObj.location.href.split("?")[0];

	leftObj.location.href = href + paramUrl;
	document.all("where_sql").value = "notDoQuery";
	document.all("extend_param").value = date+";"+costUnitID;
	//alert(date);
	f_reloadPage();
}

function f_setGrid() {
	f_setTotalDate();
}

function f_setTotalDate() {
	var account_date = document.all("extend_param").value;
	var acc_date = account_date.split(";");
	if (account_date == "") {
		document.all("account_flag").value = "2004-09";
	} else {
		document.all("account_flag").value = acc_date[0];
		document.all("cost_unit").value = acc_date[1];
	}
}

//-->
</SCRIPT>
<table class="gridTbl">
<tr class="gridData">
	<td class="gridData" ><label id="totalDate"><eam:message key = "text.finance.account_flag"/>:</label>

	<select name="account_flag">
	<%
		String strGetAccountFlag = "select  distinct account_flag  as account_flag from finance_inoust_account order by account_flag ";
		System.out.println("strGetAccountFlag = "+strGetAccountFlag);
		List listAccountFlagList = _dao.query(strGetAccountFlag);
		Map mapAccountFlag = null;
		String strAccountFlag = null;
		for (int ii=0,nn = listAccountFlagList.size();ii < nn; ii ++){
			mapAccountFlag = (Map)listAccountFlagList.get(ii);
			strAccountFlag = (String)mapAccountFlag.get("account_flag");
			System.out.println(strAccountFlag);
	%>
	<option value="<%=strAccountFlag%>"><%=strAccountFlag%></option>
	<%}%>
	</select>
		<SELECT NAME="cost_unit">
	<option value=""></option>
	<%
		String strGetCostUnit  = "select cost_unit_id ,cost_unit_name from base_cost_unit order by cost_unit_id";
		//System.out.println(strGetCostUnit);
		List listCostUnit  = _dao.query(strGetCostUnit);
		Map mapCostUnit = null;
		String strCostUnit = null;
		String strCostUnitID = null;
		for (int kk = 0 ,mm = listCostUnit.size();kk < mm;kk++){
			mapCostUnit = (Map)listCostUnit.get(kk);
			strCostUnit = (String)mapCostUnit.get("cost_unit_name");
			strCostUnitID = (String)mapCostUnit.get("cost_unit_id");
			//System.out.println(strCostUnit);
	%>
	<option value="<%=strCostUnitID%>"><%=strCostUnit%></option>
	<%}%>
	</SELECT>
	<input type="button" name="btnAccount" value="<eam:message key="btn.total2" />" onclick="f_account();">
	<eam:message key="steelement.report.money" />(<eam:message key="text.finance.device" />):<%=(String)mpCnt.get("pagenum")%>
	<eam:message key="text.finance.quantity" />(<eam:message key="default.ste.material" />):<%=(String)mpCntste.get("send_qty")%>
	<eam:message key="steelement.report.money" />(<eam:message key="default.ste.material" />):<%=(String)mpCntste.get("pagenum")%>
    <eam:message key="text.finance.quantity" />(<eam:message key="text.finance.mat" />):<%=(String)mpCntmat.get("send_qty")%>
    <eam:message key="steelement.report.money" />(<eam:message key="text.finance.mat" />):<%=(String)mpCntmat.get("pagenum")%>
	</TD>
</TR>
</TABLE>
